<?php namespace Common\Model;
use Hdphp\Model\Model;
//商品模型
class GoodsList extends  Model{
	//指定表名
	protected $table="goods_list";
	
	
	//添加
	public function store(){
		if(!$this->create()){
			return false;
		}
		$glid=$this->add();
		$list=Q('post.');
		unset($list['glnum']);
		unset($list['goods_gid']);
		unset($list['gltotal']);
		$list=implode('|',$list);
		//获得提交的数据
		$data['gattrid']=$list;
		$data['glid']=$glid;
		$this->save($data);
		
		
		
		//实例化商品表
		$gid=Q('get.gid',0,'intval');

//		p($gltotal);
		$goodsModel=new \Common\Model\Goods;
		$total=$this->where("goods_gid={$gid}")->get();
		$gtotal=0;
		foreach($total as $v){
			$gtotal=$gtotal+$v['gltotal'];
			
		}
//		$gtotal[]=$gid;
		$goodsModel->save(array('gtotal'=>$gtotal,'gid'=>$gid));
//		p($gtotal);die;
		

		return TRUE;
	}
	public function edit(){
		if(!$this->create()) return false;
//		$gid=Q("get.gid",0,'intval');
		$glid=Q('post.glid');
		$data['goods_gid']=Q('post.goods_gid');
		$data['gltotal']=Q('post.gltotal');
		$data['glnum']=Q('post.glnum');
		$list=Q('post.');
		unset($list['glnum']);
		unset($list['goods_gid']);
		unset($list['gltotal']);
		$list=implode('|',$list);
		//获得提交的数据
		$data['gattrid']=$list;
		$data['glid']=$glid;

		$this->save($data);
		
		return true;
	}




}
 ?>